package com.sneakxy.cloudbase.platform.bean.dto;

import java.util.ArrayList;
import java.util.List;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.Size;

import org.springframework.beans.BeanUtils;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.sneakxy.cloudbase.platform.bean.Role;
import com.sneakxy.cloudbase.platform.bean.ValidAdd;
import com.sneakxy.cloudbase.platform.bean.ValidEdit;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;

/**
 * 角色信息DTO
 * @author 潜行的虚影
 * @see
 */
@Data
@ApiModel("角色信息")
@EqualsAndHashCode
@JsonIgnoreProperties(ignoreUnknown = true)
public class RoleDTO implements java.io.Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = -3160953552053932317L;

	@NotBlank(groups={ValidAdd.class, ValidEdit.class})
	@Size(max=32, groups={ValidAdd.class, ValidEdit.class})
	@ApiModelProperty("角色ID")
	private String id;

	@NotBlank(groups={ValidAdd.class, ValidEdit.class})
	@Size(max=50, groups={ValidAdd.class, ValidEdit.class})
	@ApiModelProperty("角色名称")
	private String name;

	@Size(max=100, groups={ValidAdd.class, ValidEdit.class})
	@ApiModelProperty("备注")
	private String memo;

	@ApiModelProperty("排序")
	private Integer sort;

	@ApiModelProperty("创建时间")
	private String createtime;
	
	@ApiModelProperty("更新时间")
	private String updatetime;

	public static RoleDTO from(Role entity) {
		RoleDTO result = new RoleDTO();
		BeanUtils.copyProperties(entity, result);
		return result;
	}
	
	public static List<RoleDTO> from(Iterable<Role> list) {
		List<RoleDTO> result = new ArrayList<>();
		list.forEach(entity -> {
			result.add(from(entity));
		});
		return result;
	}
	
	public static Role to(RoleDTO entity) {
		Role result = new Role();
		BeanUtils.copyProperties(entity, result);
		return result;
	}
	
	public static List<Role> to(List<RoleDTO> list) {
		List<Role> result = new ArrayList<>(list.size());
		list.forEach(entity -> {
			result.add(to(entity));
		});
		return result;
	}

}
